<template>
  <div>
      <el-row>
          <el-col :span="24" align="right">
              <div style="margin-top:10px">
                <el-button @click="addNewRecord" type="primary">添加事件</el-button>
                <el-input style="width:200px" v-model="filter.name" placeholder="请输入事件名称"></el-input>
                <el-select v-model="filter.kind" placeholder="请选择事件类型">
                  <el-option :value="1" label="一般事件"></el-option>
                  <el-option :value="2" label="重大事件"></el-option>
                </el-select>
                 <el-select v-model="filter.status" placeholder="请输入事件处理状态">
                  <el-option v-for="(v,i) of EventStatus" :key="i" :label="v.sseventStatusTypeName" :value="v.sseventStatusTypeValue"></el-option>
                </el-select>
                <el-button type="primary" icon="search" @click="getInfo">搜索</el-button>
                <el-button type="primary" @click="flushAll">刷新</el-button>
              </div>
              <el-row style="margin-top:20px">
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?3:0">
                      <treeComponent style="margin-top:-52px" @GetNodeValue="GetNodeValue"></treeComponent>
                  </el-col>
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?21:24">
                      <el-table :data="list" border>
                          <el-table-column v-for="(v,k,i) in props" :key="v.id" :label="labels[i]" align="center">
                              <template scope="scope">
                                  <span v-if="k==='sex'">
                                       {{scope.row[k]==1?'男':'女'}}
                                  </span>
                                  <span v-else-if="k=='ssEventKind'">
                                    {{scope.row[k]==1?'一般事件':'重大事件'}}
                                  </span>
                                  <span v-else-if="k=='ssEventStatusTypeName'">
                                    {{getStatus(scope.row)}}
                                  </span>
                                  <span v-else>
                                      {{scope.row[k]}}
                                  </span>
                              </template>
                          </el-table-column>
                          <el-table-column label="操作" width="200" align="center">
                              <template scope="scope">
                                  <!-- <el-button type="text" v-if="scope.row.ssEventKind==3&&(scope.row.ssEventStatusTypeValue==''||scope.row.ssEventStatusTypeValue=='08')" style="color:red"
                                   @click="dealEvent(scope.row.ssEventID)">提交审核(简单事件)</el-button> -->
                                  <el-button type="text" v-if="scope.row.ssEventStatusTypeValue==null" style="color:red" @click="upEvent(scope.row.ssEventID)">上报事件</el-button>
                                  <el-button type="text" v-if="(scope.row.ssEventStatusTypeValue=='02'||scope.row.ssEventStatusTypeValue=='08')&&isDistribute(scope.row.ssEventID)" style="color:red" @click="dealEvent(scope.row.ssEventID)">处理事件(不予立案)</el-button>
                                  <el-button type="text" @click="ckDetail(scope.row.ssEventID)">查看详情</el-button>
                                  <el-button type="text" v-if="scope.row.ssEventStatusTypeValue==''" @click="editEvent(scope.row.ssEventID)">编辑</el-button>
                                  <el-button type="text" v-if="scope.row.ssEventStatusTypeValue==''" @click="deleteEvent(scope.row.ssEventID)">删除</el-button>
                              </template>
                          </el-table-column>
                      </el-table>
                       <el-pagination style="margin-top:10px;float:right" layout="prev, pager, next" :total="totalInfo"  @current-change="handleCurrentChange">
                      </el-pagination>
                  </el-col>
              </el-row>
          </el-col>
      </el-row>

     <el-dialog title="事件处理" :visible.sync="visible">
       <el-form :model="form2" label-width="100px">
            <el-form-item>
              <h1>事件基本信息</h1>
            </el-form-item>
            <el-form-item label="处理人ID">
              <el-input disabled style="width:400px" v-model="form2.dealingUserID"></el-input>
            </el-form-item>
            <el-form-item label="处理时间">
              <el-date-picker type="datetime" v-model="form2.dealingTime"></el-date-picker>
            </el-form-item>
            <el-form-item label="处理情况">
              <el-input type="textarea" v-model="form2.dealingInf"></el-input>
            </el-form-item>
            <el-form-item label="备注">
              <el-input  type="textarea" v-model="form2.remark"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="insertDealInfo">提交，下一步上传图片、视频</el-button>
            </el-form-item>
            <el-form-item v-if="form2.eventID!==''">
              <h1>图片、视频信息</h1>
            </el-form-item>
            <el-form-item v-if="form2.eventDealingID!==''">
               <el-upload
              class="upload-demo"
              :action="getDomian()+'/msmis/api/SSEvent/addSSEventDealingPictures?ID='+form2.eventDealingID"
              :file-list="fileList"
              :headers="header"
              list-type="picture">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">可上传jpg/jpeg/png文件</div>
            </el-upload>
            </el-form-item>
            <el-form-item v-if="form2.eventDealingID!==''">
              <h4>视频上传</h4>
              <el-upload
                class="upload-demo"
                drag
                :action="getDomian()+'/msmis/api/SSEvent/addSSEventDealingVideo?ID='+form2.eventDealingID"
                :headers="header"
                multiple>
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将视频拖到此处，或<em>点击上传</em></div>
              </el-upload>
            </el-form-item>
             <el-form-item align="center">
              <el-button type="primary" @click="visible = false"></el-button>
            </el-form-item>
          </el-form>
     </el-dialog>

     <el-dialog top="5%" title="查看详情" :visible.sync="visible2">
      <info :id="id"></info>
    </el-dialog>
  </div>
</template>

<script>
import treeComponent from "../../components/common/treeComponent";
import * as api from "../../api/securityManage";
import { getToken } from "../../utils/auth";
import * as socket from "@/api";
import info from "./eventInfo"

export default {
  components: {
    treeComponent: treeComponent,
    info:info
  },
  data() {
    return {
      visible: false,
      currentID: "",
      fileList: [],
      header:{
        token:getToken()
      },
      currentPage:1,
      form2: {
        eventDealingID: "",
        eventID: "",
        dealingUserID: 1, // bigint comment '处理任务的人的用户ID',
        dealingTime: "", //   datetime,
        dealingInf: "", //  varchar(1000) comment '处理情况文字描述',
        remark: "" //  varchar(500),
      },
      filter: {
        id: 1,
        name: null,
        kind: null,
        status: null,
        netGridID: null,
        page: 1,
        pageSize: 10
      },
      EventStatus: null,
      form: {
        userID: "", //        '派发任务的人的ID',
        acceptedUserID: "", // '接受任务人的用户ID号',
        startTime: "", //       datetime,
        endTime: "", //              datetime,
        remark: "" //               varchar(1000),
      },
      list: [
        {
          ssEventID: "", //                  bigint not null auto_increment,
          ssEventName: "",
          netGridID: "", //所属网格
          ssEventKind: "", //               '事件性质，如1=一般事件；2=重大事件；等',
          ssEventTypeValue: "", //          '事件类型，如杀人、放火、抢劫等',
          ssEventContent: "", //             varchar(1000),
          ssEventStartDateTime: "", //       datetime,
          // SSEventEndDateTime: "", //         datetime,
          ssEventHappenLongitude: "", //     '地理经度信息',
          ssEventHappenLatitude: "", //      '地理纬度信息',
          ssEventStatusTypeValue: "", //     '当前事件处理的最新状态',
          currentRemarks: "", //              varchar(1000),
          currentResponsiblePersonCertID: "", //  '当前经办人员身份证号',
          currentResponsiblePersonName: "", //  '当前经办人员姓名',
          currentResponsiblePersonContact: "", //'经办人员联系方式',
          netGridName: ""
        }
      ],
      totalInfo: 0,
      props: {
        ssEventName: "",
        ssEventKind: "", //               '事件性质，如1=一般事件；2=重大事件；等',
        ssEventTypeName: "", //          '事件类型，如杀人、放火、抢劫等',
        ssEventStatusTypeName: "", //     '当前事件处理的最新状态',
        ssEventStartDateTime:'',
        netGridName: "" //所属网格
      },
      labels: ["事件名称", "事件性质", "事件类型", "事件处理状态", "发生日期","所属网格"],
      id:'',
      visible2:false
    };
  },
  methods: {
    getDomian() {
      return 'http://' + window.location.host;
    },
    isDistribute(id) {
      let value;
      this.$jquery.ajax({
        url: "/msmis/api/SSEvent/isDistribute",
        headers: { token: getToken() },
        async: false,
        data: { id: id },
        success: function(res) {
          value = res.data;
        }
      });
      return value;
    },
    getStatus(obj) {
      if (obj.ssEventStatusTypeName !== null) {
        return obj.ssEventStatusTypeName;
      } else {
        return "事件待上报!";
      }
    },
    insertDealInfo() {
      this.form2.eventID = this.currentID;
      api.insertSSEventDealingBasic(this.form2).then(res => {
        if (res.code == 200) {
          this.form2.eventDealingID = res.data;
          this.$message({
            type: "success",
            message: "事件处理信息上传成功！"
          });
          socket.send({username:4,message:'有新的社会治安事件需要审核!'});
          api.updateSSEventStatus("06", this.currentID).then(res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "等待审核！"
              });
              this.getInfo();
            }
          });
        } else {
          this.$message({
            type: "error",
            message: "事件处理信息上传失败！"
          });
        }
      });
    },
    dealEvent(id) {
      this.visible = true;
      this.currentID = id;
    },
    upEvent(id) {
      this.$confirm("是否上报此事件记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          api.updateSSEventStatus("01", id).then(res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "事件上报成功!"
              });
              socket.send({username:4,message:'有新的社会治安事件上报,需要处理!'});
              this.getInfo();
            } else {
              this.$message({
                type: "error",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消上报"
          });
        });
    },
    deleteEvent(id) {
      this.$confirm("是否删除此事件记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          api.deleteSSEvent(id).then(res => {
            if (res.data) {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.getInfo();
            } else {
              this.$message({
                type: "error",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    flushAll() {
      this.filter.name = this.filter.kind = this.filter.netGridID = this.filter.status = null;
      this.getInfo();
    },
    handleCurrentChange(val) {
      this.filter.page = val;
      this.getInfo();
    },
    ckDetail(id) {
      this.id = id;
      this.visible2 = true;
    },
    addNewRecord() {
      this.$router.push("addEvent");
    },
    GetNodeValue(val) {
      this.filter.netGridID = val;
      this.getInfo();
    },
    editEvent(id) {
      this.$router.push({ path: "edit", query: { id: id } });
    },
    getInfo() {
      api.getSSEventReporterQuery(this.filter).then(res => {
        this.list = res.data.vos;
        this.totalInfo = res.data.page.totalCount;
      });
      this.filter.name = this.filter.kind = this.filter.netGridID = this.filter.status = null;
    }
  },
  mounted() {
    this.filter.id = this.$store.getters.user.userID;
    this.form2.dealingUserID = this.$store.getters.user.userID;
    this.getInfo();
    api.getSSEventCode().then(res => {
      this.EventStatus = res.data.EventStatusType;
    });
  }
};
</script>


<style scoped>

</style>
